package com.example.demo.controller;

import com.example.demo.dao.pojo.ProblemInfo;
import com.example.demo.service.ProblemService;
import com.example.demo.vo.Result;
import com.example.demo.vo.params.UpdateProblemParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ProblemController {
    @Autowired
    private ProblemService problemService;


    /**
     * 获取题目列表
     *
     * @param
     * @return
     */

//    @GetMapping("/listProblem/{page}/{pageSize}/{token}")
//    public Result listProblem(@PathVariable int page, @PathVariable int pageSize, @PathVariable String token){
//        PageParams params = new PageParams();
//        params.setPage(page);
//        params.setPageSize(pageSize);
//        params.setToken(token);
//        return problemService.listProblem(params);
//    }
    @GetMapping("/deleteProblem/{id}")
    public Result deleteProblem(@PathVariable int id){
        return problemService.deleteProblem(id);
    }

    /**
     * 通过 id 获取博客详情
     * @param id
     * @return
     */
    @GetMapping("/problem")
    public Result findProblemById(int id) {
        return problemService.findProblemById(id);
    }

    /**
     * 新增题目
     *
     * @param problemInfo
     * @return
     */
    @RequestMapping(value = "/addproblem", method = RequestMethod.POST)
    public int addProblem(ProblemInfo problemInfo) {
        return problemService.addProblem(problemInfo);
    }

    /**
     * 删除题目
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "removeproblem", method = RequestMethod.POST)
    public int removeProblem(int id) {
        return problemService.removeProblem(id);
    }


    /**
     * 修改题目
     */
    @RequestMapping("updateProblem")
    public Result updateProblem(@RequestBody UpdateProblemParams params){
        return problemService.updateProblem(params);
    }
}
